// pages/train/train-product-item/trainProductItem.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    disabled: {
      type: Boolean,
      value: false,
    },
    isProduct: {
      type: Boolean,
      value: false
    },
    item: {
      type: Object,
      value: {},
    },
    userClassify: {
      type: String,
      value: 'learning'
    },
    customerSex: {
      type: String,
      value: 'female'
    },
    from: {
      type: String,
      value: ''
    },
    trainingLibraryId: {
      type: String,
      value: ''
    },
    hasStudyPower:{
      type: Boolean,
      value: false
    },
    hasTrainPower:{
      type: Boolean,
      value: false
    },
    hasExamPower:{
      type: Boolean,
      value: false
    },
    // 是否推荐
    isRecommended:{
      type: String,
      value: 'N'
    },
    recordType:{
      type: String,
      value: ''
    },
    classType:{
      type: String,
      value: '1'
    }
  },
  options: {
    addGlobalClass: true
  },

  /**
   * 组件的初始数据
   */
  data: {
    CDNPATH:app.globalData.CDNPATH,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    learn () {
      if (this.data.disabled) {
        this.triggerEvent('disabledClick', {}, {})
        return
      }
      const { isProduct, userClassify, item,isRecommended, customerSex,trainingLibraryId,recordType, from } = this.data
      const { id, sceneId, sceneName, description, descInfo, productId, presentationId, coachingContentId = '', customerId } = item
      if (isProduct) {
        const scene = {
          sceneId,
          sceneName,
          userClassify,
          customerSex,
          trainingLibraryId
        }
        wx.navigateTo({
          url: `/pages/home-page/to-demonstration/toDemonstration?productId=${productId}&type=demonstration&presentationIds=${[presentationId]}&hasDemonstration=true&scene=${JSON.stringify(scene)}`,
        })
      } else {
        console.log('isRecommended',isRecommended)
        wx.navigateTo({
          url: `/pages/train/learning-link/learningLink?sceneId=${sceneId}&sceneName=${sceneName}&recordType=${recordType}&trainSceneId=${id}&userClassify=${userClassify}&isRecommended=${isRecommended}&customerSex=${customerSex}&coachingContentId=${coachingContentId}&trainingLibraryId=${trainingLibraryId}&description=${description}&descInfo=${descInfo}&from=${from}`
        })
      }
    },
    train () {
      if (this.data.disabled) {
        this.triggerEvent('disabledClick', {}, {})
        return
      }
      const { userClassify, item,isRecommended, customerSex, from, trainingLibraryId = '' } = this.data
      const { id, sceneId, sceneName, coachingContentId = '', description, descInfo } = item
      // const { userClassify, item, customerSex } = this.data
      // const { sceneId, sceneName } = item
      const type = 'train'
      wx.navigateTo({
        url: `/pages/train/only-train/onlyTrain?sceneId=${sceneId}&sceneName=${sceneName}&trainSceneId=${id}&userClassify=${userClassify}&isRecommended=${isRecommended}&customerSex=${customerSex}&coachingContentId=${coachingContentId}&trainingLibraryId=${trainingLibraryId}&type=${type}&description=${description}&descInfo=${descInfo}&from=${this.data.from}`
        // url: `/pages/train/only-train/onlyTrain?sceneId=${sceneId}&sceneName=${sceneName}&userClassify=${userClassify}&customerSex=${customerSex}`
      })
    },
    exam () {
      if (this.data.disabled) {
        this.triggerEvent('disabledClick', {}, {})
        return
      }
      console.log('11111====');
      // const { userClassify, item, customerSex } = this.data
      // const { sceneId, sceneName } = item
      const { userClassify, item, customerSex ,isRecommended, trainingLibraryId = '' } = this.data
      const { id, sceneId, sceneName, coachingContentId = '', description, descInfo } = item
      const type = 'exam'
      wx.navigateTo({
        url: `/pages/train/exam/exam?sceneId=${sceneId}&sceneName=${sceneName}&trainSceneId=${id}&userClassify=${userClassify}&isRecommended=${isRecommended}&customerSex=${customerSex}&coachingContentId=${coachingContentId}&trainingLibraryId=${trainingLibraryId}&type=${type}&description=${description}&descInfo=${descInfo}`
        // url: `/pages/train/exam/exam?sceneId=${sceneId}&sceneName=${sceneName}&userClassify=${userClassify}&customerSex=${customerSex}`
      })
    },
  }
})
